package com.lx.bizimpl;



import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lx.biz.Indexbiz;
import com.lx.domain.Tree;
import com.lx.domain.Vote_list;

@Service("iIndexbizimpl")
@Transactional
public class Indexbizimpl implements Indexbiz {
	@Autowired
	private SessionFactory sessionFactory;  

	public void setSessionFactory(SessionFactory sessionFactory) {  
	    this.sessionFactory = sessionFactory;  
	}  

	@Override
	public List<Tree> treelist(String id ,int role) {
		if (role==99) {
			if (id!=null &&!id.equals("")) {
				String hqlString = "FROM Tree WHERE nid = ?" ;
				Query query = sessionFactory.getCurrentSession().createQuery(hqlString);
				query.setInteger(0, Integer.parseInt(id)) ;
				return query .list() ;
			}else {
				String hqlString = "FROM Tree WHERE nid = ?" ;
				Query query = sessionFactory.getCurrentSession().createQuery(hqlString);
				query.setInteger(0, 0) ;
				return query .list() ;
			}
		}else {
			if (id!=null &&!id.equals("")) {
				String hqlString = "FROM Tree WHERE nid = ? And id <>2" ;
				Query query = sessionFactory.getCurrentSession().createQuery(hqlString);
				query.setInteger(0, Integer.parseInt(id)) ;
				return query .list() ;
			}else {
				String hqlString = "FROM Tree WHERE nid = ? And id <> 2" ;
				Query query = sessionFactory.getCurrentSession().createQuery(hqlString);
				query.setInteger(0, 0) ;
				return query .list() ;
			}
		}
		
		
	}

	@Override
	public List<Vote_list> votelist() {
		String hqlString = "FROM Vote_list" ;
		Query query = sessionFactory.getCurrentSession().createQuery(hqlString);
		return query.list();
	}

}
